#include "StdAfx.h"
#include "Alert.h"

namespace wlog {

	Hashtable^ Alert::GetFields(void)
	{
		Hashtable^ fields = gcnew Hashtable;
		fields->Add("desc", Sqlite::safeValue(this->desc));
		fields->Add("alert_time", this->alert_time);
		fields->Add("count", this->count);

		this->f_req = gcnew ArrayList;
		this->f_req->Add("desc");
		this->f_req->Add("alert_time");

		this->VerifyFields(fields);

		return fields;
	}


	ArrayList^ Alert::GetAll(void)
	{
		return this->db->CreateQuery(this->ToString())
					   ->Order("active, alert_time")
					   ->GetAll();
	}

	Hashtable^ Alert::GetAlert(void)
	{
		String^ now = System::DateTime::Now.AddDays(1).ToString(Alert::TFORMAT);

		return this->db->CreateQuery(this->ToString())
					   ->AndWhere("active = ", "1")
					   ->AndWhere("alert_time <= ", now)
					   ->Order("active, alert_time")
					   ->GetRow();
	}

}